package com.easefun.polyv.livecommon.ui.widget.magicindicator;

import androidx.viewpager.widget.ViewPager;

import com.easefun.polyv.livecommon.ui.widget.magicindicator.buildins.commonnavigator.abs.PLVCommonNavigatorAdapter;

/**
 * 简化和ViewPager绑定
 * Created by hackware on 2016/8/17.
 */

public class PLVViewPagerHelper {
    public static void bind(final PLVMagicIndicator magicIndicator, ViewPager viewPager, final PLVCommonNavigatorAdapter adapter) {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                magicIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageSelected(int position) {
                magicIndicator.onPageSelected(position);
                adapter.setPosition(position);
                adapter.notifyDataSetChanged();
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                magicIndicator.onPageScrollStateChanged(state);
            }
        });
    }
}
